/*
 * Client.java
 *
 * Created on February 26, 2007, 10:38 AM
 */

package gui;

import networking.*;

/**
 *
 * @author  Alex Filby
 *
 */
public class Client extends javax.swing.JFrame {
    private clientComm cComm;
    private String data = "AppleTestData.db";
    private String serverlist;
    
    /** Creates new form Client */
    public Client() {
        initComponents();
        setup();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        statusL = new javax.swing.JLabel();
        statusText = new javax.swing.JLabel();
        setsL = new javax.swing.JLabel();
        setsCounter = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        connectB = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        serverL = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        dataF = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Innsystems Client v1.0");
        statusL.setFont(new java.awt.Font("Arial", 0, 12));
        statusL.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        statusL.setText("Status:");

        statusText.setFont(new java.awt.Font("Arial", 0, 12));
        statusText.setText("Not connected");

        setsL.setFont(new java.awt.Font("Arial", 0, 12));
        setsL.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        setsL.setText("Sets Completed:");

        setsCounter.setFont(new java.awt.Font("Arial", 0, 12));
        setsCounter.setText("00");

        jButton1.setText("Stop");
        jButton1.setEnabled(false);

        connectB.setText("Connect");
        connectB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                connectServer(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel1.setText("Server List:");

        serverL.setText("Enter filename");

        jLabel2.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel2.setText("Data File:");

        dataF.setText("Enter datafile");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(layout.createSequentialGroup()
                                .add(42, 42, 42)
                                .add(statusL, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 60, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(layout.createSequentialGroup()
                                .addContainerGap()
                                .add(setsL, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .add(layout.createSequentialGroup()
                                .addContainerGap()
                                .add(jLabel1))
                            .add(layout.createSequentialGroup()
                                .addContainerGap()
                                .add(jLabel2)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(setsCounter, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 51, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(statusText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 94, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(serverL, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 134, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(dataF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 134, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(108, Short.MAX_VALUE)
                        .add(connectB)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton1)))
                .add(39, 39, 39))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(statusL, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
                    .add(statusText))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(setsL, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(setsCounter, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .add(17, 17, 17)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(serverL, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(14, 14, 14)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(dataF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(14, 14, 14)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(connectB)
                    .add(jButton1))
                .add(36, 36, 36))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void connectServer(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectServer
// Connect to server
        data = dataF.getText();
        dataF.setEditable(false);
        serverlist = serverL.getText();
        serverL.setEditable(false);
        LocateServer ls = new LocateServer(serverlist);
        ClientSend send = new ClientSend(cComm, ls.getServer());
        statusText.setText("Connected...");
        ls = null;
        RecieveClient rec = new RecieveClient(cComm);
        NNrun nn = new NNrun(cComm, data);
        
    }//GEN-LAST:event_connectServer
    
    private void setup() {
        cComm = new clientComm();
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Client().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton connectB;
    private javax.swing.JTextField dataF;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField serverL;
    private javax.swing.JLabel setsCounter;
    private javax.swing.JLabel setsL;
    private javax.swing.JLabel statusL;
    private javax.swing.JLabel statusText;
    // End of variables declaration//GEN-END:variables
    
}
